package com.csi.controller;

import com.csi.service.LocationService;
import com.csi.utils.JsonResult;
import com.csi.utils.ReturnResults;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 位置管理
 */
@RequestMapping("/location")
@RestController
@Tag(name = "Area",description = "地区查询接口")
public class LocationController {

    @Autowired
    private LocationService locationService;

    /**
     * 根据上一级id查询地区(省、市、县)
     * @param areaId
     * @return
     */
    @GetMapping("area")
    @Operation(summary = "地区查询",description = "省市区查询全国地区")
    public Object getArea(@RequestParam("id") long areaId){
        Map<String,Object> areaList =  locationService.getAllArea(areaId);
        if (!areaList.isEmpty() && areaList != null ){
            return  new JsonResult<>(ReturnResults.ACCESS_SUCCESS,areaList,"查找成功！");
        }
        return new JsonResult<>(ReturnResults.ACCESS_FAILED,"查找失败！");
    }
}
